package com.bos.web.action;

import com.bos.domian.base.Courier;
import com.bos.service.CourierService;
import com.bos.web.BaseAction;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import org.apache.poi.util.SystemOutLogger;
import org.apache.struts2.convention.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.List;
import java.util.Optional;

/**
 * @author misterWei
 * @create 2018年11月13号:09点22分
 * @mailbox mynameisweiyan@gmail.com
 */
@ParentPackage("json-default")
@Namespace("/")
@Actions
@Controller
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)//多例的
public class CourierAction extends BaseAction<Courier> {
    @Autowired
    private CourierService courierService;

    @Action(value = "courier_save", results = {@Result(location = "/pages/base/courier.html")})
    public String courierSave() {
        courierService.save(model);

        return SUCCESS;
    }

    //分页操作
    //分页操作

    @Action(value = "courier_pageQuery", results = {@Result(type = "json")})
    public String courierPageQuery() {
        ActionContext.getContext().getValueStack()
                .push(courierService.pageQuery(page - 1, rows, model));
        return SUCCESS;
    }

    private String ids;  //快递员id
    private Boolean flag; //true还原//false作废

    public void setIds(String ids) {
        this.ids = ids;
    }

    public void setFlag(Boolean flag) {
        this.flag = flag;

    }

    @Action(value = "delBatch", results = {@Result(location = "/pages/base/courier.html")})
    public String delBatch() {
        System.err.println(flag);
        courierService.delAndstart(ids, flag);
        return SUCCESS;
    }
    //查询没有与定区关联的快递员
    @Action(value = "noassociationCourier",results = {@Result(type = "json")})
    public String noassociationCourier(){
       List<Courier> couriersList = courierService.noassociationCourier();
       ActionContext.getContext().getValueStack().push(couriersList);
        return SUCCESS;
    }
}
